var express = require('express');
var path = require('path');
var app = express();
var bodyParser = require('body-parser');
var favicon = require('serve-favicon');

// 路由
var bloglist = require('./routes/bloglist');
var about = require('./routes/about');
var works = require('./routes/works');
var post = require('./routes/post');


var env = process.env.NODE_ENV || 'development';
var dbUrl = "mongodb://127.0.0.1:19999/test2";
if (env == 'development') {
    dbUrl = "mongodb://127.0.0.1:27017/test3";

}

var mongoose = require('mongoose');
mongoose.connect(dbUrl, { useMongoClient: true });
mongoose.Promise = global.Promise;

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));




app.use('/', bloglist);
app.use('/about', about);
app.use('/works', works);
app.use("/post", post);

module.exports = app;
